home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Date.sig < prev    next >
Encoding:
Text File  |  1996-07-03  |  3.9 KB  |  94 lines  |  [TEXT/R*ch]

  1. (* Date -- SML Standard Library *)
  2.  
  3. datatype weekday = Mon | Tue | Wed | Thu | Fri | Sat | Sun
  4.  
  5. datatype month = Jan | Feb | Mar | Apr | May | Jun
  6.                | Jul | Aug | Sep | Oct | Nov | Dec
  7.  
  8. datatype date = DATE of {
  9.     year   : int,            (* e.g. 1995 *)
  10.     month  : month,
  11.     day    : int,               (* 1-31  *)
  12.     hour   : int,               (* 0-23  *)
  13.     minute : int,               (* 0-59  *)
  14.     second : int,               (* 0-61 (allowing for leap seconds) *)
  15.     wday   : weekday option,
  16.     yday   : int option,        (* 0-365 *)
  17.     isDst  : bool option        (* daylight savings time in force *)
  18.   }
  19.  
  20. exception Date
  21.  
  22. val fromTime : Time.time -> date
  23. val fromUTC  : Time.time -> date
  24. val toTime   : date -> Time.time
  25.  
  26. val compare  : date * date -> ordering
  27.  
  28. val toString   : date -> string
  29. val fmt        : string -> date -> string
  30. val fromString : string -> date option
  31. val scan       : {getc : 'a -> (char * 'a) option} -> 'a -> (date * 'a) option
  32.  
  33. (* These functions convert times to dates and vice versa, and format
  34.    and scan dates.
  35.  
  36.    [fromTime t] returns the local date at time t.  The fields year,
  37.    month, day, hour, minute, and second are as expected.  The fields
  38.    wday and yday are guaranteed to be SOME _, whereas isDst may be
  39.    NONE if the system cannot determine whether daylight savings time
  40.    is in effect at the given time.  Corresponds to the ANSI C function 
  41.    `localtime'.
  42.  
  43.    [fromUTC t] is similar to fromTime, but returns the UTC date at
  44.    time t.  Corresponds to the ANSI C function `gmtime'.
  45.  
  46.    [toTime dt] returns the time corresponding to the local date dt.
  47.    Ignores the yday and wday fields (it does not matter whether they
  48.    are NONE or SOME _).  Uses the isDst time field if it is present
  49.    (SOME _) and cannot be calculated from the given date.  May raise
  50.    Date if the given date is invalid.  Raises Time.Time if the Date
  51.    cannot be represented as a Time.time value.  At least the dates in
  52.    the interval 1970-2030 can be represented as Time.time values.  
  53.    Corresponds to the ANSI C function `mktime'.
  54.  
  55.    The weekday of a given date dt can be computed as
  56.    #wday(fromTime(toTime dt)); yday and isDst are similar.
  57.  
  58.    [compare(d1, d2)] returns LESS, EQUAL, or GREATER, according 
  59.    as date d1 precedes, equals, or follows d2 in time.  Lexicographically
  60.    compares the dates, ignoring wday, yday, and isDst, and does not detect
  61.    invalid dates.
  62.  
  63.    [toString dt] returns a 24 character string representing the date dt
  64.    in the following format:  
  65.               Wed Mar 08 19:06:45 1995
  66.    It ignores the weekday (if supplied) and recomputes it on the basis of 
  67.    the other fields; the result may be wrong if the date is outside the
  68.    representable Time.time range.  Raises Date if the given date is invalid.
  69.    Corresponds to the ANSI C function `asctime'.
  70.  
  71.    [fmt fmtstr dt] formats the date dt according to the format string
  72.    fmtstr, by calling the ANSI C function `strftime'.  For instance,
  73.    (fmt "%A" dt) returns the full name of the weekday, such as
  74.    "Monday", for the given date.  For a full description of the fmt
  75.    syntax, consult a description of strftime.  Ignores the weekday
  76.    field (if supplied) and recomputes it on the basis of the other
  77.    fields; the result may be wrong if the date is outside the
  78.    representable Time.time range.  Raises Date if the given date is
  79.    invalid.
  80.  
  81.    [fromString s] scans a 24-character date from the string s, after
  82.    possible initial whitespace (blanks, tabs, newlines).  The format
  83.    of the string must be precisely as produced by toString.  The
  84.    fields yday and isDst in the resulting date will be NONE.  No check
  85.    of the consistency of the date (weekday, date in the month, ...) is
  86.    performed.
  87.  
  88.    [scan {getc} src] scans a 24-character date from the stream src,
  89.    using the stream accessor getc.  Otherwise works as fromString.  In
  90.    case of success, returns SOME(date, rst) where date is the scanned
  91.    date and rst is the remainder of the stream; otherwise returns
  92.    NONE.
  93. *)
  94.